/**
 * Created by zhengrunqiang on 2016-12-19.
 */
myApp.controller("RecommendUserCtrl", ['$scope', '$http', '$routeParams', '$restUrls', '$post', '$rootScope', function ($scope, $http, $routeParams, $restUrls, $post, $rootScope) {
    //获取推荐人信息
    $scope.GetRecommendUser = function () {
        $http({ method: "GET", url: $restUrls["getRecommendUser"], params: {} }).success(function (result) {
            if (result.success == 1) {
                $scope.user = result.data;
            }
        }).error(function (data, status, headers, config) {
            $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
        });
    }
    $scope.GetRecommendUser();


    $scope.sumbitone = false;
    //保存推荐人信息
    $scope.SaveRecommendUser= function (user) {
        if ($scope.sumbitone) {
            return;
        }
        if ($scope.RecommendUserForm.$valid) {
            $scope.showOneError = true;
            return;
        }
        var parameters = {
            telephone:user.telephone
        }
        $post($restUrls["addRecommend"], parameters).success(function (result) {
            if (result.success == 1) {
                window.history.back();
            } else {
                $.scojs_message(result.message, $.scojs_message.TYPE_ERROR);
            }
        }).error(function (data, status, headers, config) {
            $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
        });
    }
}]);
